//
//  RegisterFirstViewController.m
//  1243
//
//  Created by 我的 on 16/4/6.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "RegisterFirstViewController.h"
#import "RegisterSecondViewController.h"
#import "NetWorkTools.h"
#import "RegiseterTwoViewController.h"
@interface RegisterFirstViewController ()<UITextFieldDelegate>
/**
 *  手机号码
 */
@property (weak, nonatomic) IBOutlet UITextField *phoneNumText;
/**
 *  密码
 */
@property (weak, nonatomic) IBOutlet UITextField *passwordText;
/**
 *  重复密码
 */
@property (weak, nonatomic) IBOutlet UITextField *repeatPasswordText;
/**
 *  姓名
 */
@property (weak, nonatomic) IBOutlet UITextField *nameText;
/**
 *  交易密码
 */
@property (weak, nonatomic) IBOutlet UITextField *dealPasswordText;
/**
 *  立即注册
 */
@property (weak, nonatomic) IBOutlet UIButton *registerButton;

@property (weak, nonatomic) IBOutlet UITextField *eMail;

@property (nonatomic, strong)NSDictionary *dic;

@property (weak, nonatomic) IBOutlet UITextField *shenFenZhengTextField;
@end

@implementation RegisterFirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:44 / 255.0 green:87 / 255.0 blue:229 / 255.0 alpha:1];
     self.navigationController.navigationBar.translucent = NO;
    [self setupUI];
    
    self.dealPasswordText.delegate = self;
    self.dealPasswordText.tag = 100;
    
    self.nameText.delegate = self;
    self.nameText.tag = 101;
    
    self.eMail.delegate = self;
    self.eMail.tag = 100;
    
    self.dealPasswordText.delegate = self;
    self.dealPasswordText.tag = 101;
    
    self.shenFenZhengTextField.delegate = self;
    self.shenFenZhengTextField.tag = 100;
}

- (void)setupUI
{
    self.title = @"注册";
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(clickBtnBack)];
    self.navigationItem.leftBarButtonItem = leftItem;
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    [self.registerButton addTarget:self action:@selector(didClickRegisterButton) forControlEvents:UIControlEventTouchUpInside];

}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self resignFitstResponedTextField];
}


- (void)clickBtnBack {
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (void)resignFitstResponedTextField {
    [self.phoneNumText resignFirstResponder];
    [self.passwordText resignFirstResponder];
    [self.repeatPasswordText resignFirstResponder];
    [self.nameText resignFirstResponder];
    [self.dealPasswordText resignFirstResponder];
    [self.shenFenZhengTextField resignFirstResponder];
    [self.eMail resignFirstResponder];

}

- (void)clearPassWordTextField {
    self.passwordText.text = nil;
    self.repeatPasswordText.text = nil;
    self.dealPasswordText.text = nil;
}

- (IBAction)clickNextBtn:(UIButton *)sender {
//    
//    [self.navigationController pushViewController:[[RegisterSecondViewController alloc] init] animated:YES];
    
    
}

- (void)didClickRegisterButton {
    [self resignFitstResponedTextField];
    
    if (self.passwordText.text != self.repeatPasswordText.text) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"两次密码输入有误,请重新输入" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        
        [alert show];
        
        [self clearPassWordTextField];
        
        return;
    }
    
    if (self.passwordText.text == self.dealPasswordText.text) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"交易密码与登录密码重复,请重新设置" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        
        [self clearPassWordTextField];
        
        return;
    }
    
   self.dic= @{
                           
                           @"UserName":self.phoneNumText.text,
                           @"Password":self.repeatPasswordText.text,
                           @"Buy_Password":self.dealPasswordText.text,
                           @"RealName":self.nameText.text,
                           @"Email":self.eMail.text,
                           @"V_Number":@"1001",
                           @"V_Name":@"小黑",
                           @"LastLoginTime":@"2016-04-12T15:47:20.6938427+08:00",
                           @"PNumber1":@"1002",
                           @"PName1":@"小兰",
                           @"PNumber2":@"1003",
                           @"PName2":@"小红;",
                           @"PNumber3":@"1004",
                           @"PName3":@"小白",
                           @"UserRole":@"VIP",
                           @"Money":@"0.0000",
                           @"fh_Money":@"0.00",
                           @"gq_Money":@"0.0000",
                           @"gwj_Money":@"0.00",
                           @"Dl_Money":@"0.0000",
                           @"Status":@"1",
                           @"CreateTime":@"2016-04-12T15:47:20.6928426+08:00",
                           @"Remark":@"iOS客户端测试"
                           };

    
    RegiseterTwoViewController *a = [[RegiseterTwoViewController alloc] initWithNibName:@"RegiseterTwoViewController" bundle:[NSBundle mainBundle]];
    a.dic = self.dic;
    [self.navigationController pushViewController:a animated:YES];

}

- (IBAction)pushBtn:(id)sender {
   
}




-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField.tag == 101|| textField.tag == 100) {
        CGRect frame = textField.frame;
        int offset = frame.origin.y + 80 - (self.view.frame.size.height - 216.0);//键盘高度216
        
        //将视图的Y坐标向上移动offset个单位，以使下面腾出地方用于软键盘的显示
        if(offset > 0)
            self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height);
        
        [UIView commitAnimations];
        
    }
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    
    self.view.frame =CGRectMake(0, 64, width, height);
    //    NSLog(@"%@", textField.text);
}



@end
